package ma.platform.server.student.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import ma.plaform.server.common.log.annotation.SysLog;
import ma.platform.server.core.exception.CheckedException;
import ma.platform.server.core.util.R;
import ma.platform.server.student.entity.TbComboInfo;
import ma.platform.server.student.entity.TbComboInfo;
import ma.platform.server.student.entity.TbStudent;
import ma.platform.server.student.service.TbComboInfoService;
import ma.platform.server.student.service.TbComboInfoService;
import ma.platform.server.student.service.TbStudentService;
import org.apache.commons.collections.CollectionUtils;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/combo")
public class ComboController {

    @Resource
    private TbComboInfoService tbComboInfoService;

 

    @GetMapping("/page")
    public R page(@ParameterObject Page page, @ParameterObject TbComboInfo comboInfo) {
        return R.ok(tbComboInfoService.page(page, Wrappers.<TbComboInfo>lambdaQuery()
                .like(StrUtil.isNotBlank(comboInfo.getName()), TbComboInfo::getName, comboInfo.getName())));
    }

    /**
     * 添加学生
     *
     * @return success、false
     */
    @SysLog("添加套餐")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('tb_comboInfo_add')")
    public R save(@Valid @RequestBody TbComboInfo comboInfo) {
        tbComboInfoService.save(comboInfo);
        return R.ok(comboInfo);
    }

    /**
     * 删除学生
     *
     * @param ids ID
     * @return R
     */
    @SysLog("删除套餐")
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('tb_comboInfo_del')")
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(tbComboInfoService.removeByIds(Lists.newArrayList(ids)));
    }

    /**
     * 修改学生
     *
     * @return success/false
     */
    @PutMapping
    @SysLog("修改套餐")
    @PreAuthorize("@pms.hasPermission('tb_comboInfo_edit')")
    public R updateById(@Valid @RequestBody TbComboInfo comboInfo) {
        tbComboInfoService.updateById(comboInfo);
        return R.ok();
    }

    /**
     * 通过ID查询信息
     * @param id ID
     */
    @GetMapping("/details/{id}")
    public R getById(@PathVariable Long id) {
        return R.ok(tbComboInfoService.getById(id));
    }



}
